// var to = window.location.href;




var userpass;
var shouji;
$(".mi input").change(function () {
    userpass = $("#user-pass").val();

    if (!(/^[a-zA-Z\d]{6,16}$/.test(userpass))) {
        $(".mi p").text(`密码为6-16字母或数字密码`).show();
    } else {
        $(".mi p").hide();

      
    }
})

$(".hao input").change(function () {
    shouji = $("#shouji").val();
    if (!(/^1[3456789]\d{9}$/.test(shouji))) {
        $(".hao p").text(`手机号输入错误`).show();
    } else if (shouji == "") {
        $(".hao p").text(`请输入手机号`).show();
    } else {
        $(".hao p").hide()


    }
})


dl(userpass,shouji)

function dl(userpass,shouji) {
    $(".dl").click(function () {
        console.log("可点");
        console.log(shouji);
        console.log(userpass);
        
        
        var shouji = $("#shouji").val();
        var userpass = $("#user-pass").val();
            $.ajax({
                url: "dl.php",
                dataType: "json",
                async: false,
                data: {
                    "shouji": shouji,
                    "userpass": userpass
                },
                type: "post",
                success: function (data) {
                    if (data) {
                        // alert("登陆成功");
                        window.location.href="http://localhost/ck/xiangmu2/xiangmu.html"; 
                        if ($(".dl-checkbox").prop("checked") == true) {
                            $.cookie("userid", data["id"], { expires: 7, path: '/' });
                            $.cookie("shouji", data["shouji"], { expires: 7, path: '/' });
                            console.log("打钩");
                        } else {
                            $.cookie("userid", data["id"], { path: '/' });
                            $.cookie("shouji", data["shouji"], { path: '/' });
                        }
                    } else {
                        alert("密码错误")
                    }
                }
            }) 
     
   
    })
}
